#
# Copyright 2016 National Renewable Energy Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

@PACKAGE_INIT@

# Compilers use by OpenFAST build
set(OpenFAST_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
set(OpenFAST_C_COMPILER "@CMAKE_C_COMPILER@")
set(OpenFAST_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@")

# Compiler flags used by OpenFAST build
set(OpenFAST_CXX_COMPILER_FLAGS "@CMAKE_CXX_FLAGS@")
set(OpenFAST_C_COMPILER_FLAGS "@CMAKE_C_FLAGS@")
set(OpenFAST_Fortran_COMPILER_FLAGS "@CMAKE_Fortran_FLAGS@")

set_and_check(OpenFAST_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(OpenFAST_LIBRARY_DIRS "@PACKAGE_LIB_INSTALL_DIR@")
set_and_check(OpenFAST_FTNMOD_DIR "@PACKAGE_FTNMOD_INSTALL_DIR@")

set(OpenFAST_LIBRARIES "openfastlib")
set(OpenFAST_CPP_LIBRARIES "openfastcpplib")

include("${CMAKE_CURRENT_LIST_DIR}/OpenFASTLibraries.cmake")

set(OpenFAST_HAS_CXX_API @OpenFAST_HAS_CXX_API@)
set(OpenFAST_FOUND TRUE)

if (NOT OpenFAST_FIND_COMPONENTS)
  if (OpenFAST_HAS_CXX_API)
    set(OpenFAST_FIND_COMPONENTS "openfastcpplib;openfastlib")
  else()
    set(OpenFAST_FIND_COMPONENTS "openfastlib")
  endif()
endif ()

foreach (comp IN LISTS OpenFAST_FIND_COMPONENTS)
  if (${comp} STREQUAL "openfastcpplib")
    if (NOT OpenFAST_HAS_CXX_API)
      set(OpenFAST_${comp}_FOUND FALSE)
      message(WARNING "OpenFAST ${comp} NOT found")
      if(OpenFAST_FIND_REQUIRED_${comp})
        set(OpenFAST_FOUND FALSE)
      endif()
    else()
      set(OpenFAST_${comp}_FOUND TRUE)
    endif()
  else()
    set(OpenFAST_${comp}_FOUND TRUE)
  endif()
endforeach ()

check_required_components(OpenFAST)
